package com.lame.sbconstant.product.strategy;

import com.lame.detect.vo.ClassMeta;
import com.lame.sbconstant.product.vo.ProductDesc;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.tree.ParseTree;

public class DfControllerStrategy  extends ProductActorAdapter{
    private String tpl = "${PACKAGE}.controller;\n"+
            "import ${BASE_PKG}.entity.${ENTITY};\n"+
            "import ${BASE_PKG}.service.I${ENTITY}Service;\n"+
            "import com.baomidou.mybatisplus.core.conditions.Wrapper;\n" +
            "import com.baomidou.mybatisplus.core.mapper.BaseMapper;\n" +
            "import com.baomidou.mybatisplus.core.metadata.IPage;\n" +
            "import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;\n"+
            "import org.jeecg.common.aspect.annotation.AutoLog;\n" +
            "import org.jeecg.common.system.base.controller.JeecgController;\n" +
            "import org.jeecg.common.system.query.QueryGenerator;\n" +
            "import org.jeecg.common.system.vo.LoginUser;\n"+
            "import com.baomidou.mybatisplus.extension.plugins.pagination.Page;\n" +
            "import org.apache.ibatis.annotations.Param;\n" +
            "import org.apache.ibatis.annotations.Select;\n" +
            "import javax.servlet.http.HttpServletRequest;\n" +
            "import javax.servlet.http.HttpServletResponse;\n"+
            "import io.swagger.annotations.Api;\n" +
            "import io.swagger.annotations.ApiOperation;\n"+
            "import org.springframework.beans.factory.annotation.Autowired;\n" +
            "import org.springframework.web.bind.annotation.DeleteMapping;\n" +
            "import org.springframework.web.bind.annotation.GetMapping;\n" +
            "import org.springframework.web.bind.annotation.PostMapping;\n" +
            "import org.springframework.web.bind.annotation.PutMapping;\n" +
            "import org.springframework.web.bind.annotation.RequestBody;\n" +
            "import org.springframework.web.bind.annotation.RequestMapping;\n" +
            "import org.springframework.web.bind.annotation.RequestMethod;\n" +
            "import org.springframework.web.bind.annotation.RequestParam;\n" +
            "import org.springframework.web.bind.annotation.RestController;\n"+
            "import lombok.extern.slf4j.Slf4j;\n" +
            "import org.apache.commons.collections.CollectionUtils;\n" +
            "import org.apache.commons.lang3.StringUtils;\n" +
            "import org.jeecg.common.api.vo.Result;\n" +
            "import org.jeecg.common.aspect.annotation.AutoLog;\n"+
            "@Api(tags=\"${ENTITY}\")\n"+
            "@RestController(\"/${ENTITY}\")\n"+
            "@Slf4j\n"+
            "public class ${ENTITY}Controller extends JeecgController<${ENTITY}, I${ENTITY}Service>{\n" +
            "    @Autowired\n" +
            "    private I${ENTITY}Service thisService;\n"+
            "  @AutoLog(value = \"分页列表查询\")\n" +
            "    @ApiOperation(value = \"分页列表查询\", notes = \"分页列表查询\")\n" +
            "    @GetMapping(value = \"/list\")\n" +
            "    public Result<?> queryPageList(${ENTITY} model,\n" +
            "                                   @RequestParam(name = \"pageNo\", defaultValue = \"1\") Integer pageNo,\n" +
            "                                   @RequestParam(name = \"pageSize\", defaultValue = \"10\") Integer pageSize,\n" +
            "                                   HttpServletRequest req) {\n" +
            "        QueryWrapper<${ENTITY}> queryWrapper = QueryGenerator.initQueryWrapper(model, req.getParameterMap());\n" +
            "        Page<${ENTITY}> page = new Page<${ENTITY}>(pageNo, pageSize);\n" +
            "        IPage<${ENTITY}> pageList = thisService.page(page, queryWrapper);\n"+
            "        return Result.OK(pageList);\n" +
            "    }\n" +
            "\n" +
            "    /**\n" +
            "     * 添加\n" +
            "     *\n" +
            "     * @param model\n" +
            "     * @return\n" +
            "     */\n" +
            "    @AutoLog(value = \"添加\")\n" +
            "    @ApiOperation(value = \"添加\", notes = \"添加\")\n" +
            "    @PostMapping(value = \"/add\")\n" +
            "    public Result<?> add(@RequestBody ${ENTITY} model) {\n" +
            "        return Result.OK(\"添加成功！\");\n" +
            "    }\n" +
            "\n" +
            "    /**\n" +
            "     * 编辑\n" +
            "     *\n" +
            "     * @param certChainMgr\n" +
            "     * @return\n" +
            "     */\n" +
            "    @AutoLog(value = \"编辑\")\n" +
            "    @ApiOperation(value = \"编辑\", notes = \"编辑\")\n" +
            "    @PutMapping(value = \"/edit\")\n" +
            "    public Result<?> edit(@RequestBody ${ENTITY} model) {\n" +
            "        return Result.OK(\"编辑成功!\");\n" +
            "    }\n" +
            "\n" +
            "    /**\n" +
            "     * 通过id删除\n" +
            "     *\n" +
            "     * @param id\n" +
            "     * @return\n" +
            "     */\n" +
            "    @AutoLog(value = \"通过id删除\")\n" +
            "    @ApiOperation(value = \"通过id删除\", notes = \"通过id删除\")\n" +
            "    @DeleteMapping(value = \"/delete\")\n" +
            "    public Result<?> delete(@RequestParam(name = \"id\", required = true) String id) {\n" +
            "        return Result.OK(\"删除成功!\");\n" +
            "    }\n" +
            "\n" +
            "\n" +
            "    /**\n" +
            "     * 通过id查询\n" +
            "     *\n" +
            "     * @param id\n" +
            "     * @return\n" +
            "     */\n" +
            "    @AutoLog(value = \"通过id查询\")\n" +
            "    @ApiOperation(value = \"通过id查询\", notes = \"通过id查询\")\n" +
            "    @GetMapping(value = \"/queryById\")\n" +
            "    public Result<?> queryById(@RequestParam(name = \"id\", required = true) String id) {\n" +
            "\n"+
            "        return Result.OK(certChainMgr);\n" +
            "    }\n" +
            "\n" +
            "}\n";

    @Override
    public String product(Parser parser, ParseTree parseTree, ClassMeta classMeta) {
        return TplTools.generate(classMeta, tpl);
    }

    @Override
    public ProductDesc productDesc(Parser parser, ParseTree parseTree, ClassMeta classMeta) {
        final String generate = TplTools.generate(classMeta, tpl);
        return new ProductDesc("./controller/" + classMeta.getName() + "Controller.java", generate, false);
    }
}
